import { z } from "zod";
import path from "path";
import { fileURLToPath } from "url";
import { getDetailAnalyzeProblemPrompt } from "../../prompts/index.js";
import { getMemoryDir } from "../../utils/paths.js";

// 详细分析问题工具
// Detail Analyze Problem Tool
export const detailAnalyzeProblemSchema = z.object({
  problemDescription: z
    .string()
    .min(10, {
      message: "问题描述不能少于10个字符，请提供更详细的问题描述",
    })
    .describe("问题的详细描述，包含背景信息、现象表现和初步观察"),
  analysisDepth: z
    .enum(['basic', 'detailed', 'comprehensive'])
    .optional()
    .default('detailed')
    .describe("分析深度级别：basic(基础分析)、detailed(详细分析)、comprehensive(全面分析)"),
  contextInfo: z
    .string()
    .optional()
    .describe("相关的上下文信息，如项目背景、技术栈、约束条件等（可选）")
});

export async function detailAnalyzeProblem({
  problemDescription,
  analysisDepth = 'detailed',
  contextInfo
}: z.infer<typeof detailAnalyzeProblemSchema>) {
  // 获取基础目录路径
  // Get base directory path
  const __filename = fileURLToPath(import.meta.url);
  const __dirname = path.dirname(__filename);
  const PROJECT_ROOT = path.resolve(__dirname, "../../..");
  const MEMORY_DIR = await getMemoryDir();

  // 使用prompt生成器获取最终prompt
  // Use prompt generator to get the final prompt
  const prompt = await getDetailAnalyzeProblemPrompt({
    problemDescription,
    analysisDepth,
    contextInfo: contextInfo || '',
    memoryDir: MEMORY_DIR,
  });

  return {
    content: [
      {
        type: "text" as const,
        text: prompt,
      },
    ],
  };
}
